package com.ruoyi.lab.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lab.domain.LabSupplier;
import com.ruoyi.lab.service.ILabSupplierService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商Controller
 * 
 * @author mojar
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/lab/supplier")
public class LabSupplierController extends BaseController
{
    @Autowired
    private ILabSupplierService labSupplierService;



    /**
     * 查询供应商列表
     */
    @PreAuthorize("@ss.hasPermi('lab:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabSupplier labSupplier)
    {
        startPage();
        List<LabSupplier> list = labSupplierService.queryList(labSupplier);
        return getDataTable(list);
    }

    @GetMapping("listAll")
    public AjaxResult listAll(LabSupplier labSupplier){
        List<LabSupplier> list = labSupplierService.queryList(labSupplier);
        return success(list);
    }


    /**
     * 导出供应商列表
     */
    @PreAuthorize("@ss.hasPermi('lab:supplier:export')")
    @Log(title = "供应商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabSupplier labSupplier)
    {
        List<LabSupplier> list = labSupplierService.queryList(labSupplier);
        ExcelUtil<LabSupplier> util = new ExcelUtil<>(LabSupplier.class);
        util.exportExcel(response, list, "供应商数据");
    }

    /**
     * 获取供应商详细信息
     */
    @PreAuthorize("@ss.hasPermi('lab:supplier:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(labSupplierService.getById(id));
    }

    /**
     * 新增供应商
     */
    @PreAuthorize("@ss.hasPermi('lab:supplier:add')")
    @Log(title = "供应商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabSupplier labSupplier)
    {
        return toAjax(labSupplierService.save(labSupplier));
    }

    /**
     * 修改供应商
     */
    @PreAuthorize("@ss.hasPermi('lab:supplier:edit')")
    @Log(title = "供应商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabSupplier labSupplier)
    {
        return toAjax(labSupplierService.updateById(labSupplier));
    }

    /**
     * 删除供应商
     */
    @PreAuthorize("@ss.hasPermi('lab:supplier:remove')")
    @Log(title = "供应商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(labSupplierService.removeBatchByIds(ids));
    }
}
